using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace WindowsApplication4
{
    public class Compaign
    {
        DataTable dtTargets;
        DataRow drCompaign;
        Compaigns compaigns;


        public Target AddTarget(Village villageToAttack, string targetDescription)
        {
            DataRow newTarget = compaigns.dtTargets.Rows.Add(new object[] { null
                , drCompaign[Compaigns.CONSTS.dtCompaigns.Columns.CompaignIDIndex]
                , villageToAttack.ID
            ,targetDescription});

            return new Target(newTarget, this.compaigns);
        }

        public Compaign(DataRow compaign, Compaigns compaigns)
        {
            drCompaign = compaign;
            this.compaigns = compaigns;
        }

        public string Name
        {
            get
            {
                return drCompaign[Compaigns.CONSTS.dtCompaigns.Columns.NameIndex].ToString();
            }
            set 
            {
                drCompaign[Compaigns.CONSTS.dtCompaigns.Columns.NameIndex] = value;
            }
        }

        public System.Collections.Generic.List<Target> Targets
        {
            get
            {
                DataRow[] rows = drCompaign.GetChildRows(Compaigns.CONSTS.Relations.CompaignToTarget);
                if (rows.Length == 0)
                {
                    return new List<Target>(0);
                }
                else
                {
                    List<Target> targets = new List<Target>(rows.Length);

                    foreach (DataRow dr in rows)
                    {
                        targets.Add(new Target(dr ,compaigns));
                    }

                    return targets;
                }
            }
        }

        internal void Delete()
        {

            foreach (Target target in Targets)
            {
                target.Delete();
            }
            drCompaign.Delete();
            //compaigns.dsCompaign.AcceptChanges();
        }
    }
}
